package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.AlbumUpdateNewDTO;
import cn.tedu.csmall.product.service.IAlbumService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@Api(tags = "03.相册管理模块")
@RequestMapping("/albums")
public class AlbumController {
    @Autowired
    private IAlbumService albumService;
    @PostMapping("/add-new")
    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid AlbumAddNewDTO albumAddNewDTO){
        log.debug("即将处理添加相册的请求....");
        log.debug("albumAddNewDTO="+albumAddNewDTO);
        albumService.addNew(albumAddNewDTO);
        return JsonResult.ok();
    }
    @ApiOperation("删除相册")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiImplicitParam(name = "id",value = "相册id",required = true,dataType = "long")
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("即将处理删除相册请求,参数:id={}",id);
        albumService.delete(id);
        return JsonResult.ok();
    }
    @ApiOperation("修改相册")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update")
    public JsonResult<Void> update(@Valid AlbumUpdateNewDTO albumUpdateNewDTO){
        log.debug("即将处理修改相册请求,参数:{}",albumUpdateNewDTO);
        albumService.update(albumUpdateNewDTO);
        return JsonResult.ok();
    }
}
